import { isNavigationFailure } from "vue-router"
import { fi } from "element-plus/es/locale"
import request from "./request"
import request_claim from "./request_claim"

export const req_login = (account: string, password: string) => {
    return request({
        url: '/account/login',
        method: 'post',
        data: {
            "account": account,
            "password": password
        }
    })
}

export const req_Scholar = (scholar_id: string) => {
    return request({
        url: '/entity/scholar/' + scholar_id,
        method: 'get'
    })

}

export const req_register = (user_name: string, email: string, password: string) => {
    return request({
        url: '/account/register',
        method: 'post',
        data: {
            "user_name": user_name,
            "email": email,
            "password": password
        }
    })
}

export const req_adminRegister = (user_name: string, email: string, password: string) => {
    return request({
        url: '/admin-register',
        method: 'post',
        data: {
            "user_name": user_name,
            "email": email,
            "password": password
        }
    })
}

export const req_logout = () => {
    return request({
        url: '/account/logout',
        method: 'post'
    })
}

export const req_starScholarGet = () => {
    return request({
        url: '/star/scholar/list',
        method: 'get'
    })
}

export const req_scholarToWork = (scholar_id: string) => {
    return request({
        url: '/relation/get_papers_by_authorships/' + scholar_id,
        method: 'get'
    })
}

export const req_claim = (data: any) => {
    return request_claim({
        url: '/portal/claim',
        method: 'post',
        transformRequest: [function (data) {
           console.log(data.get('file').length)
           return data
        }],
        data: data
    })
}

//改变关注状态
export const req_starScholarAdd = (scholar_id: string) => {
    return request({
        url: '/star/scholar/add',
        method: 'post',
        data: {
            "id": scholar_id
        }
    })
}

export const req_starScholarRemove = (scholar_id: string) => {
    return request({
        url: '/star/scholar/remove',
        method: 'post',
        data: {
            "id": scholar_id
        }
    })
}

export const req_starScholarAsk = (scholar_id: string) => {
    return request({
        url: `/star/scholar/ask?id=${scholar_id}`,
        method: 'get'
    })
}

export const req_userGet = () => {
    return request({
        url: '/account/current',
        method: 'get'
    })
}

export const req_searchSuggestions = (target: string, keyword: string) => {
    return request({
        url: `/search/suggest`,
        method: 'get',
        params: {
            target: target,
            keyword: keyword,
        }
    });
}

// 获取门户申领列表
export const req_applyList = () => {
    return request({
        url: '/review/list',
        method: 'get',
    })
}

// 驳回申领门户请求的接口
export const req_rejectClaim = (claimId: string) => {
    return request({
        url: '/review/reject',
        method: 'post',
        data: {
            "claim_id": claimId
        },
    });
}

//通过申领门户请求的接口
export const req_approveClaim = (claimId: string) => {
    return request({
        url: '/review/approve',
        method: 'post',
        data: {
            "claim_id": claimId
        }
    });
};

// 获取文献收藏列表
export const req_getPaperStar = () => {
    return request({
        url: `/star/paper/list`,
        method: 'GET',
    })
}
// 获取文献相关列表
export const req_getPaperRefList = (works_idList) => {
    return request({
        url: `/list/paper`,
        method: 'post',
        data: {
            'id_list': works_idList,
        }
    })
}

// 移除收藏文献
export const req_removePaperStar = (works_id: string) => {
    return request({
        url: `/star/paper/remove`,
        method: 'POST',
        data: {
            'id': works_id,
        }
    })
}

// 新增收藏文献
export const req_addPaperStar = (works_id: string) => {
    return request({
        url: `/star/paper/add`,
        method: 'POST',
        data: {
            'id': works_id,
        }
    })
}

// 询问收藏文献
export const req_askPaperStar = (works_id: string) => {
    return request({
        url: `/star/paper/ask`,
        method: 'get',
        params: {
            'id': works_id,
        }
    })
}

// 获取当前组织所有作品
export const req_getOrgWorks = (org_id: string) => {
    return request({
        url: `/org/works`,
        method: 'get',
        data: {
            'org_id': org_id
        }
    })
}

// 修改用户名
export const req_modifyUsername = (new_user_name: string) => {
    return request({
        url: `/account/modify/user_name`,
        method: 'post',
        data: {
            "new_user_name": new_user_name,
        }
    })
}
// 修改邮箱
export const req_modifyEmail = (new_email: string) => {
    return request({
        url: `/account/modify/email`,
        method: 'post',
        data: {
            "new_email": new_email,
        }
    })
}
// 修改密码
export const req_modifyPwd = (old_pwd: string, new_pwd: String) => {
    return request({
        url: `/account/modify/password`,
        method: 'post',
        data: {
            "origin_password": old_pwd,
            "new_password": new_pwd,
        }
    })
}
// 修改个人介绍
export const req_modifyInfor = (information: string) => {
    return request({
        url: `/portal/modify/information`,
        method: 'post',
        data: {
            "information": information,
        }
    })
}

//获取单个核心对象-期刊的接口
export const req_getVenueInfo = (venueId: string) => {
    return request({
        url: `/entity/venue/${venueId}`,
        method: 'get',
    });
};

//获取单个核心对象-学者的接口
export const req_getScholarInfo = (scholarId: string) => {
    return request({
        url: `/entity/scholar/${scholarId}`,
        method: 'get',
    });
};

//获取单个核心对象-文献的接口
export const req_getWorksInfo = (worksId: string) => {
    return request({
        url: `/entity/paper/${worksId}`,
        method: 'get',
    });
};

//获取单个核心对象-组织的接口
export const req_getOrgInfo = (orgId: string) => {
    return request({
        url: `/entity/org/${orgId}`,
        method: 'get',
    });
};

//获取单个核心对象-领域的接口
export const req_getConceptInfo = (conceptId: string) => {
    return request({
        url: `/entity/concept/${conceptId}`,
        method: 'get',
    });
};


//获取平台数据相关接口：
//主页获取平台数据分析
export const req_getStatistics = () => {
    return request({
        url: `/statistics`,
        method: 'GET',
    })
}

//搜索相关接口：
//聚合搜索
export const req_getSearchBuckets = (keyword: string, target: string, field: string) => {
    return request({
        url: `/search/buckets?keyword=${keyword}&target=${target}&field=${field}`,
        method: 'get',
    });
};

//搜索
export const req_getSearch = (keyword: string, target: string, page: number, sort_key: string,
    agg: {
        venue: string[],
        concepts: string[],
        type: string[],
        level: string[]
    }
) => {
    return request({
        url: `/search?keyword=${keyword}&target=${target}&page=${page}&sort_key=${sort_key}`,
        method: 'post',
        data: {
            "agg": agg
        }
    });
};

//以下是获取关联的核心对象的相关接口：
//期刊->文献
export const req_getPapersByPrimaryLocation = (venueId: string) => {
    return request({
        url: `/relation/get_papers_by_primary_location/${venueId}`,
        method: 'get',
    });
};

//组织->学者
export const req_getScholarsByLastKnownInstitution = (insId: string) => {
    return request({
        url: `/relation/get_scholars_by_last_known_institution/${insId}`,
        method: 'get',
    });
};

//领域->文章
export const req_getPapersByXConcepts = (insId: string) => {
    return request({
        url: `/relation/get_papers_by_concepts/${insId}`,
        method: 'get',
    });
};

//领域->学者
export const req_getScholarsByXConcepts = (insId: string) => {
    return request({
        url: `/relation/get_scholars_by_x_concepts/${insId}`,
        method: 'get',
    });
};

// 获取门户简介
export const req_getPortalInfo = (scholarId) => {
    return request({
        url: `/portal/info/${scholarId}`,
        method: 'get',
    });
};